<template>
  <header class="fxs"
          :class="[type == 3 ? 'order':'']">
    <div class="info"
         v-if="type != 3">
      <span class="fontGilroy">{{navData.total_commissions}}</span>
      <p>我的{{navData.commission_name}}(元)</p>
    </div>
    <div class="info2"
         v-else>
      <div class="other fontGilroy">
        <div>
          <span>
            {{Data.total_commissions}}
          </span>
          <p>我的{{navData.commission_name}}(元)</p>
        </div>
        <div>
          <span>
            {{Data.total_fee}}
          </span>
          <p>{{navData.ftitle_agency_order}}总金额(元)</p>
        </div>
      </div>
    </div>
    <nav>
      <div v-if="navData.show_dl_product"
           class="nav-item"
           :class="[0 == type?'active':'']"
           @click="selectNav('dlsGoods')">
        <p class="num fontGilroy">{{navData.agent_item_count}}</p>
        <p class="name">{{navData.agent_item_name}}</p>
        <i></i>
      </div>
      <div v-if="navData.show_dl_agencies"
           class="nav-item"
           :class="[1 == type?'active':'']"
           @click="selectNav('nextLevelAgency')">
        <p class="num fontGilroy">{{navData.agency_total}}</p>
        <p class="name">{{navData.ftitle_agencies}}</p>
        <i></i>
      </div>
      <div v-if="navData.show_dl_agency_user"
           class="nav-item"
           :class="[2 == type?'active':'']"
           @click="selectNav('nextLevelAgencyUser')">
        <p class="num fontGilroy">{{navData.agency_user_total}}</p>
        <p class="name">{{navData.ftitle_agency_user}}</p>
        <i></i>
      </div>
      <div class="nav-item"
           v-if="navData.show_dl_agency_order"
           :class="[3 == type?'active':'']"
           @click="selectNav('agencyOrder')">
        <p class="num fontGilroy">{{navData.agency_order_total}}</p>
        <p class="name">{{navData.ftitle_agency_order}}</p>
        <i></i>
      </div>
    </nav>
  </header>
</template>

<script>
import Vue from 'vue'
import { getDlsOtherInfo } from '@/api/user/dls/dlsApi'
export default Vue.extend({
  props: {
    type: Number,
    Data: {
      type: Object
    },
    keyword: {
      type: String,
      default: ''
    },
    keywordClick: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      navData: {}
    }
  },
  watch: {
    keywordClick() {
      this.init()
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      getDlsOtherInfo({
        keyword: this.keyword,
        user_type: this.type == 1 ? 'agent' : this.type == 2 ? 'member' : ''
      }).then(res => {
        if (res.status == 1) {
          this.navData = res.data
          this.changeTitle()
        } else {
          this.$Error(res.msg)
        }
      })
    },
    selectNav(path) {
      // TODO 小程序跳转处理
        window.location.href = '/' + path
    },
    changeTitle() {
      const routerName = this.$route.name
      let docTitle = null
      switch (routerName) {
        case 'dls-goods':
          docTitle = this.navData.agent_item_name
          break
        case 'next-level-agency':
          docTitle = this.navData.ftitle_agencies
          break
        case 'next-level-agency-user':
          docTitle = this.navData.ftitle_agency_user
          break
        case 'agency-order':
          docTitle = this.navData.ftitle_agency_order
          break
      }
        wx.setNavigationBarTitle({
          title: docTitle
        })
    }
  }
})
</script>

<style lang="scss">
@import "src/styles/variables";
@import "src/styles/mixin";
header {
  position: relative;
  width: 100%;
  .info {
    text-align: center;
    color: $default;
    background: url("https://img.wifenxiao.com/h5-wfx/images/user/fenxiaoGood_bg.png")
      center/cover no-repeat;
    overflow: hidden;
    height: 210px;
    padding-top: 56px;
    box-sizing: border-box;
    span {
      display: block;
      font-size: 50px;
      font-weight: bold;
    }
    p {
      margin-top: 20px;
      font-size: 26px;
      color: #ffd9dd;
    }
  }
  .info2 {
    background: url("https://img.wifenxiao.com/h5-wfx/images/user/fenxiaoGood_bg.png")
      center/cover no-repeat;
    text-align: center;
    margin: 0 auto;
    color: $default;
    overflow: hidden;
    height: 210px;
    padding-top: 56px;
    box-sizing: border-box;
    span {
      display: block;
      font-size: 50px;
      font-weight: bold;
    }
    p {
      margin-top: 20px;
      font-size: 26px;
      color: #ffd9dd;
    }
    .other {
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      &::before {
        content: "";
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 1px;
        height: 80px;
        background-color: #ff7c86;
      }
      div {
        flex: 1;
      }
    }
  }
  nav {
    width: 100%;
    height: 135px;
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    // overflow: hidden;
    .nav-item {
      flex: 1;
      height: 100%;
      position: relative;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      p {
        text-align: center;
        &.num {
          font-size: 32px;
          color: #f30c23;
          font-weight: bold;
        }
        &.name {
          font-size: 24px;
          color: #666;
          margin-top: 18px;
        }
      }
      &.active i {
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        height: 6px;
        width: 96px;
        @include gradient(right, rgba(242, 11, 34, 1), rgba(242, 11, 34, 0.2));
      }
      // &::after {
      //   position: absolute;
      //   top: 50%;
      //   right: 0;
      //   width: 0;
      //   height: 30px;
      //   transform: translateY(-50%);
      //   content: "";
      //   border: 0.5px solid #e8e8e8;
      //   // background: black;
      // }
      // &:last-child {
      //   &::after {
      //     border: none;
      //   }
      // }
    }
  }
}
</style>
